package it.tcon.xbeedriver;

import com.rapplogic.xbee.api.AtCommand;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeAddress16;
import com.rapplogic.xbee.api.XBeeAddress64;
import com.rapplogic.xbee.api.XBeeException;
import com.rapplogic.xbee.api.XBeeRequest;
import com.rapplogic.xbee.api.zigbee.ZNetRemoteAtRequest;
import com.rapplogic.xbee.api.zigbee.ZNetTxRequest;
import com.rapplogic.xbee.util.ByteUtils;

public class XBeeSend {
	private XBee xbee;
	
	public XBeeSend(XBee xbee){
		this.xbee = xbee;
	}
	
	public void sendAtCommand(String at) throws XBeeException{
			AtCommand msg = new AtCommand(at);
			xbee.sendAsynchronous(msg);
	}
	public void sendRemoteAtCommand(String command,XBeeAddress64 addr64,XBeeAddress16 addr16) throws XBeeException{
		//xbee.sendAsynchronous(new ZNetRemoteAtRequest(XBeeRequest.DEFAULT_FRAME_ID,addr64,XBeeAddress16.ZNET_BROADCAST,false,command));
		
		//xbee.sendAsynchronous(new ZNetRemoteAtRequest(xbee.getNextFrameId(),addr64,XBeeAddress16.ZNET_BROADCAST,true,command));
		//ZNetTxRequest request = new ZNetTxRequest(xbee.getNextFrameId(),addr64, XBeeAddress16.ZNET_BROADCAST,ZNetTxRequest.DEFAULT_BROADCAST_RADIUS,ZNetTxRequest.UNICAST_OPTION, ByteUtils.stringToIntArray(command));
		xbee.sendAsynchronous(new ZNetRemoteAtRequest(XBeeRequest.DEFAULT_FRAME_ID, addr64, XBeeAddress16.ZNET_BROADCAST, false, command));
		//xbee.sendAsynchronous(new ZNetRemoteAtRequest(xbee.getNextFrameId(),addr64,addr16,false,command));
	}	
}
